package com.ex.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ex.model.ProductModel;

@Controller   // 说明当前是1个控制器对象
@RequestMapping(value="/product")  // 地址
//@CrossOrigin(origins = "*", allowedHeaders="*")
public class ProductController {


	@RequestMapping(value="/login")
	public String login() {
		
		
		return "/product/detail.html";
	}
			
	
	

	@RequestMapping(value="/detail")
	@ResponseBody // 返回结果是JSON数据
	public Object detail(
			@RequestParam(value="productId") Integer id,
			@RequestParam(value="callback", required=false) String callback
			) {
		
		ProductModel p = new ProductModel();

		p.setProductId(id);
		p.setCount(10);
		p.setAddress("长沙");
		p.setPrice(100.0);
		
		Map<String,Object> map = new HashMap<String,Object>();

		map.put("ret", 0);
		map.put("data", p);
		
		MappingJacksonValue mapping = new MappingJacksonValue(map);
		mapping.setJsonpFunction(callback);
		
		return mapping;
	}
	
	
}
